package com.example.bottomnavigationbar;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import com.ashokvarma.bottomnavigation.BadgeItem;
import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;

import java.util.Map;

public class MainActivity extends AppCompatActivity {
    private BottomNavigationBar navigationBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        navigationBar = findViewById(R.id.id_bnb);
        //1.0 navigationBar显示
        //B
        navigationBar.addItem(new BottomNavigationItem(R.drawable.b_pic,"about")
        .setActiveColorResource(R.color.lan));
        //C
        navigationBar.addItem(new BottomNavigationItem(R.drawable.c_pic,"before")
                .setActiveColorResource(R.color.hese));
        //G
        navigationBar.addItem(new BottomNavigationItem(R.drawable.g_pic,"go")
                .setActiveColorResource(R.color.daokese));
        //
        navigationBar.addItem(new BottomNavigationItem(R.drawable.n_pic,"no")
                .setActiveColorResource(R.color.fense));
        //z
        navigationBar.addItem(
                new BottomNavigationItem(R.drawable.z_pic, "element")
                        .setActiveColorResource(R.color.lvse)
                        .setBadgeItem(new BadgeItem()
                                .setBackgroundColorResource(android.R.color.holo_red_dark) //设置角标背景色
                                .setText("99") //设置角标的文字
                                .setTextColorResource(android.R.color.white) //设置角标文字颜色
                                .setHideOnSelect(true) //在选中时是否隐藏角标
                        )
        );

        //最后初始化
        navigationBar.initialise();

        //2.0navigationBar监听事件
        navigationBar.setTabSelectedListener(new BottomNavigationBar.OnTabSelectedListener() {
            @Override
            public void onTabSelected(int position) {
                Toast.makeText(MainActivity.this,"第"+position+"个",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onTabUnselected(int position) {
            }

            @Override
            public void onTabReselected(int position) {

            }
        });


    }
}
